package com.example.androidhw02_1;


import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;

public class MainActivity extends Activity {

	ListView listView;
	
	MyAdapter mAdapter;
	
	ArrayList<TagAndWords> mList = new ArrayList<TagAndWords>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		String[] tags = getResources().getStringArray(R.array.tags);
		String[] words00 = getResources().getStringArray(R.array.words00);
		String[] words01 = getResources().getStringArray(R.array.words01);
		String[] words02 = getResources().getStringArray(R.array.words02);
		String[] words03 = getResources().getStringArray(R.array.words03);
		String[] words04 = getResources().getStringArray(R.array.words04);
		String[] words05 = getResources().getStringArray(R.array.words05);
		String[][] wordsList = {
				words00, words01, words02, words03, words04,
				words05
		};
		
		TagAndWords[] mData;
		
		// number of dataIndex
		int dataIndex = tags.length;
		for( int i = 0; i < wordsList.length; i++){
			dataIndex += wordsList[i].length;
		}
		// mData length reset
		mData = new TagAndWords[dataIndex];
		dataIndex = 0;
		// input resources into mData from tags & wordsList
		for( int i = 0; i < tags.length; i++){
			mData[dataIndex] = new TagAndWords(tags[i], true);
			dataIndex++;
			for( int j = 0; j < wordsList[i].length; j++){
				mData[dataIndex] = new TagAndWords(wordsList[i][j], false);
				dataIndex++;
			}
		}
		
		listView = (ListView)findViewById(R.id.listView);
		setData(mData);
		
		mAdapter = new MyAdapter(this, mList);
		listView.setAdapter(mAdapter);
		
	}

	private void setData(TagAndWords[] mData) {
		// TODO Auto-generated method stub
		for(TagAndWords str : mData)
			mList.add(str);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
}
